package com.wzy.webdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Controller
public class HelloController {

    @RequestMapping(value = "/hello")
    @ResponseBody
    public String hello(){
        return "Hello Spring Boot";
    }

    @RequestMapping("/userlist")
    public String userList(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        map.put("id",0);
        map.put("name","张三");
        map.put("age",18);
        map.put("address","北湖区天桥");

        request.setAttribute("users",Arrays.asList(map));
        request.setAttribute("name","<h2>小明</h2>");

        return "userList";
    }

    @GetMapping({"/toLogin","/"})
    public String toLogin(){
        return "login";
    }

    @GetMapping({"/loginjsp"})
    public String toLoginJsp(Model model){
        model.addAttribute("name","helloJsp");
        return "hello";
    }
}
